<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />

		<title></title>
		<script src="../../js/mui.min.js"></script>
		<script src="../../js/addunits.js"></script>
		<link href="../../css/mui.min.css" rel="stylesheet" />
		<!--App自定义的css-->
		<link rel="stylesheet" href="../../css/mui.min.css">
		<link rel="stylesheet" href="../../css/global.css">
		<link rel="stylesheet" type="text/css" href="../../css/app.css" />
		<script src="../../js/getURLParam.js"></script>
	</head>

	<body>
		<nav id="navid" class="mui-bar mui-bar-tab" style=";background-color: red;display:none;text-align:center;">
			<a id="vclduibi" class="mui-tab-item" href="#">
				<span class="ui-icon-trash" style="color:white">开始对比</span>
			</a>
		</nav>
		<div class="mui-content" >
			<div id="load" style="text-align: center;"><img src="../../images/loading.gif" style="vertical-align:middle"/>正在加载...</div>
			<ul class="mui-table-view" id="list" style="font-size:14px">
			</ul>
		</div>
		
		<div style="width: 100%;text-align: center;position: fixed;bottom: 20px;">
					<span style="color:grey;font-size:15px">该功能仅支持最近90天数据分析</span>
		
		</div>
		
		<div id="error"></div>
		<script>
			mui.init({
				swipeBack: true //启用右滑关闭功能
			});
			var selected = "";
			var totalvcl=0;
			var arr = new Array();
			mui('.mui-table-view').on('change', 'input', function() {
			var value = this.checked?"true":"false";
			});
			function check(obj){
				if(obj.checked){
					selected+=obj.id+",";
					arr = selected.substring(0,selected.length-1).split(",");
					if(arr.length>2){
						document.getElementById(arr[0]).checked=false;
						var array=new Array();
						var tempid = arr[2];
						array[0]=arr[1];
						array[1]=tempid;
						arr=array;
						selected = arr[0]+","+arr[1]+",";
					}
				}else{ 
					if(selected.indexOf(obj.id)>-1){
						selected=selected.replace(obj.id+",","");
						arr=selected.replace(",","").split(",");
					}
				}
				if(selected.length>0){
					document.getElementById("navid").style.display="block"
				}else{
					document.getElementById("navid").style.display="none"
				}
			}
			var sessionid=GetQueryString("sessionid");
			var accountid=GetQueryString("accountid");
	        var proversion=GetQueryString("proversion");
	        var content = "";
	        var contentioc = document.getElementById("list")
	        getanalist();
	        function getanalist(){
		        mui.ajax('../../../APP/anayList', {
					data: {
						param: '{"proVersion":"' + proversion + '","accountId":"' + accountid + '","sessionid":"' + sessionid + '","data":{"type":"1"}}'
					},
					dataType: 'jsonp', //服务器返回json格式数据
					type: 'post', //HTTP请求类型
					timeout: 100000, //超时时间设置为10秒；
					success: function(data) {
						var jsonObj = window.JSON.parse(data);
						if (jsonObj.resultcode == "1") {
							//获取返回数据的data
							var resultdata = jsonObj.data;
							if (null != resultdata) {
								totalvcl = resultdata.length;
								for(var i=0;i<resultdata.length;i++){
									
									
									content+='<li class="mui-table-view-cell mui-media">';
									content+='<input class="mui-media-object mui-pull-left" style="height:20px;width:20px;margin-top:10px" type="checkbox" onclick="check(this)"  id="'+i+'" value="'+resultdata[i].vclid+'_'+resultdata[i].betime+'_'+resultdata[i].endtime+'"/>';
									content+='<img class="mui-media-object mui-pull-right" src="../../images/drawable-hdpi/delect.png"  onclick="del(\''+resultdata[i].vclid+'_'+resultdata[i].betime+'_'+resultdata[i].endtime+'\')"/>';
									content+='<div class="mui-media-body">'
									content+='<P style="font-size: 14px;line-height:18px"><span style="font-size:17px;color:black">'+resultdata[i].vclnum+'</span>&nbsp;&nbsp;&nbsp;&nbsp;'+addunit(resultdata[i].perkmoil,"L/100km")+'</P>'
									content+='<P style="font-size: 14px;line-height:18px">'+resultdata[i].betime+"~"+resultdata[i].endtime+'</P>'
									content+='</div>'
									content+='</li>';
								}
								/*content+=content+='<li class="mui-table-view-cell mui-media">';
								content+='<div class="mui-media-body">'
								content+='<P style="font-size: 16px;line-height:18px;text-align:center;font-weight:bolder;color:#000000">该功能仅支持最近90天数据分析</P>'
								content+='</div>'
								content+='</li>';*/
								document.getElementById("load").style.display="none";
								contentioc.innerHTML=content;
							} else {
								contentioc.innerHTML="请添加车辆进行对比";
							}
				
						} else {
							contentioc.innerHTML="请求出错："+jsonObj.resultcode;
						}
					},
					error: function(xhr, type, errorThrown) {
					//	contentioc.innerHTML="error";
					}
				});
			}
			function gocompare(){
				if(arr.length<=0){
					mui.toast("请选择对比数据");
				}else{
					var param=""
					for(var i=0;i<arr.length;i++){
						param += document.getElementById(arr[i]).value+",";
					}
					param = param.substring(0,param.length-1);
					window.location.href="vclcompare.html?sessionid="+sessionid+"&accountid="+accountid+"&proversion="+proversion+"&param="+param;
				}
			}
			function del(obj){
				mui.ajax('../../../APP/anayList', {
					data: {
						param: '{"proVersion":"' + proversion + '","accountId":"' + accountid + '","sessionid":"' + sessionid + '","data":{"type":"3","vclId":"'+obj.split("_")[0]+'","beTime":"'+obj.split("_")[1]+'","endTime":"'+obj.split("_")[2]+'"}}'
					},
					dataType: 'jsonp', //服务器返回json格式数据
					type: 'post', //HTTP请求类型
					timeout: 100000, //超时时间设置为10秒；
					success: function(data) {
						var jsonObj = window.JSON.parse(data);
						if (jsonObj.resultcode == "1") {
							mui.toast("删除成功");
							content="";
							getanalist();
						} else {
							mui.toast("删除失败！请重新操作");
						}
					},
					error: function(xhr, type, errorThrown) {
					}
					
				});
				//访问日志
				postLog("专家-删除",accountid,proversion);
			}
			function goclear(){
				var btnArray = ['取消', '确定'];
				mui.confirm('', '你确定要清空对比列表吗？', btnArray, function(e) {
				if (e.index == 1) {
					mui.ajax('../../../APP/anayList', {
					data: {
						param: '{"proVersion":"' + proversion + '","accountId":"' + accountid + '","sessionid":"' + sessionid + '","data":{"type":"4"}}'
					},
					dataType: 'jsonp', //服务器返回json格式数据
					type: 'post', //HTTP请求类型
					timeout: 100000, //超时时间设置为10秒；
					success: function(data) {
						var jsonObj = window.JSON.parse(data);
						if (jsonObj.resultcode == "1") {
							mui.toast("操作成功");
							content="";
							document.getElementById("list").innerHTML="请添加车辆进行对比";
						} else {
							mui.toast("操作失败！请重新操作");
						}
					},
					error: function(xhr, type, errorThrown) {
					}
				});
					mui.toast('你确认了解除绑定');
				} else {
					//mui.toast('你取消了解除绑定');
				}
			})
			}
			document.getElementById("vclduibi").addEventListener("tap",function(){
				if(arr.length==2){//选取了2辆车
					var value1=document.getElementById(arr[0]).value;
					var value2=document.getElementById(arr[1]).value;
					window.webkit.messageHandlers.execompare.postMessage("2_"+value1+","+value2);
				}else{
					var value1=document.getElementById(arr[0]).value;
					window.webkit.messageHandlers.execompare.postMessage("1_"+value1);
				}
			})
		</script>
	</body>

</html>